/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {number[][]}
 */
var levelOrderBottom = function(root) {
    const res=[],queue=[root]
    if(!root)return res
    while(queue.length){
        let len=queue.length,temp=[]
        for(let i=1;i<=len;i++){
            let node=queue.shift()
            temp.push(node.val)
            node.left&&queue.push(node.left)
            node.right&&queue.push(node.right)
        }
        res.push(temp)
    }
       return res.reverse()
    };